const mysql = require('mysql2/promise')
const dbConfig = require('../config/db.config.js')
const pool = mysql.createPool(dbConfig.dbOption)

// 测试连接
pool.ping = async () => {
  const connection = await pool.getConnection();
  try {
    await connection.ping();
	console.log('数据库连接成功');
  } catch {
	console.error('数据库连接失败:', err);
  } finally {
    connection.release();
	// pool.releaseConnection(connection)
	console.error('数据库连接已释放');
  }
}

pool.ping()

module.exports = pool